package com.qc.controller.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.qc.entity.HeightEntity;
import com.qc.entity.OrderEntityVo;
import com.qc.pageUtil.page.page.Page;
import com.qc.pageUtil.page.page.PageModel;
import com.qc.pageUtil.page.page.PageModelList;
import com.qc.pageUtil.page.vo.NewsAndNav;
import com.qc.service.OrderService;

@Controller
@RequestMapping("/web")
public class WebOrderController {
    
    @Resource
    private OrderService orderService;

    /**
     * 订单首页
     * @return
     */
    @RequestMapping(value = "/toOrderIndex", produces = "text/html;charset=UTF-8")
    public ModelAndView toOrderIndex() {
        ModelAndView mav = new ModelAndView("/order/dingdan_list");
        
        return mav;
    }
    
    /**
     * 订单列表展示
     * @param request
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @RequestMapping(value = "/toListAllOrder", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String toListAllOrder(HttpServletRequest request) {
        
        String bNickName = request.getParameter("bNickName");
        String mNickName = request.getParameter("mNickName");
        String orderNumber = request.getParameter("orderNumber");
        String orderState = request.getParameter("orderState");
        String isPay = request.getParameter("isPay");
        //当前页面
        int pageNo = Integer.parseInt(request.getParameter("pageNo"));
        //每页显示多少条
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        
        //根据条件总数
        int recordCount = orderService.getListOrderCount(bNickName, mNickName, orderNumber, orderState, isPay);
        
        //根据条件查询当前页数据
        List<HeightEntity> list = orderService.getAllOrder(bNickName, mNickName, orderNumber, orderState, isPay, pageNo, pageSize);
        
        //分页查询公共类
        Page<HeightEntity> page = new Page<HeightEntity>(pageNo, recordCount,pageSize);
        page.setList(list);//设置结果集  
        PageModelList<HeightEntity> pageModel = new PageModelList<HeightEntity>(page, "#", PageModel.NUM_MODEL,"doPage","1");//设置页码显示类型  
        //4 组装带翻页导航功能的对象
        NewsAndNav  objs = new NewsAndNav(list, pageModel.getPageModel());
        
        return JSONObject.fromObject(objs).toString();
        
    }
    
    /**
     * 订单详细
     * @return
     */
    @RequestMapping(value = "/toOrderInformIndex", produces = "text/html;charset=UTF-8")
    public ModelAndView toOrderInformIndex(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/order/dingdan_chakan");
        String orderId = request.getParameter("orderId");
        
        OrderEntityVo orderEntityVo = orderService.getOrderId(orderId);
        
        mav.addObject("orderEntityVo",orderEntityVo);
        return mav;
    }
    
    /**
     * 订单日程
     * @return
     */
    @RequestMapping(value = "/toOrderrichen", produces = "text/html;charset=UTF-8")
    public ModelAndView toOrderrichen(HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/sec/sec_richeng2");
        String orderId = request.getParameter("orderId");
        
        List scheduleEntity = orderService.getOrderScheduleId(orderId);
        mav.addObject("list",scheduleEntity);
        
        return mav;
    }
}
